package com.zb.system.controller;


import com.zb.annotation.SystemLog;
import com.zb.constant.OperationLogModuleType;
import com.zb.constant.OperationLogType;
import com.zb.result.Result;
import com.zb.service.ZjServicePageService;
import com.zb.system.service.ConServicePageService;
import com.zb.utils.TokenUtil;
import com.zb.vo.ServicePageQrVo;
import com.zb.vo.ServicePageSelectVo;
import com.zb.vo.ServicePageTitleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 系统服务页面表 前端控制器
 * </p>
 *
 * @author WEN
 * @since 2023-10-31
 */
@Api(tags = "服务页面类接口")
@RestController
@RequestMapping("/system/service/page")
public class ZjServicePageController {
    @Resource
    private ConServicePageService conServicePageService;
    @Resource
    private ZjServicePageService servicePageService;

    @SystemLog(moduleType = OperationLogModuleType.SYTEM_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "服务页面 - 同步服务页面")
    @ApiOperation("同步服务页面")
    @GetMapping("/syncServicePage")
    public Result syncServicePage(HttpServletRequest request) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        conServicePageService.syncServicePage(custAccId);
        return Result.success("同步服务页面成功");
    }

    @ApiOperation("获取服务页面列表")
    @PostMapping("/getList")
    public Result getList(HttpServletRequest request, @RequestBody ServicePageSelectVo selectVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        return Result.success("获取服务页面列表成功").data(conServicePageService.getList(custAccId, selectVo));
    }

    @SystemLog(moduleType = OperationLogModuleType.SYTEM_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "服务页面 - 批量启用或禁用服务页面")
    @ApiOperation("批量启用或禁用服务页面")
    @PutMapping("/disable")
    public Result disable(@RequestParam @ApiParam(value = "服务页面状态：false-启用，true-禁用", example = "false") boolean status,
                          @RequestBody @ApiParam(value = "服务页面ID", required = true) List<Long> ids) {
        servicePageService.updateDisableBatchById(ids, status);
        return Result.success(status? "禁用服务页面成功" : "启用服务页面成功");
    }

    @ApiOperation("根据页面ID获取页面标题详情")
    @GetMapping("/ServicePageTitleDetail/{id}")
    public Result ServicePageTitleDetail(@PathVariable @ApiParam(value = "服务页面ID", required = true) Long id) {
        return Result.success("获取页面标题详情成功").data("row", conServicePageService.ServicePageTitleDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.SYTEM_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "服务页面 - 修改服务页面标题与状态")
    @ApiOperation("修改服务页面标题与状态")
    @PutMapping("/udpateServicePageTitle")
    public Result udpateServicePageTitle(@RequestBody @Valid ServicePageTitleVo pageTitleVo) {
        servicePageService.udpateServicePageTitle(pageTitleVo);
        return Result.success("修改成功");
    }

    @ApiOperation("根据页面ID获取二维码详情")
    @GetMapping("/getServicePageQrDetail/{id}")
    public Result getServicePageQrDetail(@PathVariable @ApiParam(value = "服务页面ID", required = true) Long id) {
        return Result.success("获取二维码详情成功").data("row", conServicePageService.getServicePageQrDetail(id));
    }

    @SystemLog(moduleType = OperationLogModuleType.SYTEM_MODULE_TYPE, type = OperationLogType.UPDATE, remark = "服务页面 - 修改服务页面二维码信息")
    @ApiOperation("修改服务页面二维码信息")
    @PutMapping("/updateServicePageQr")
    public Result updateServicePageQr(HttpServletRequest request, @RequestBody @Valid ServicePageQrVo servicePageQrVo) {
        Long custAccId = TokenUtil.getcustAccIdByToken(request);
        servicePageService.updateServicePageQr(custAccId, servicePageQrVo);
        return Result.success("修改成功");
    }

}
